<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #div1 {
            margin: 0 auto;
            display: flex;
            justify-content: center;
            align-items: center;
            width: 300px;
            height: 300px;
            border: 3px solid skyblue;
        }

        #div2 {
            display: flex;
            justify-content: center;
            align-items: center;
            width: 200px;
            height: 200px;
            border: 3px solid khaki;
        }

        #div3 {
            width: 100px;
            height: 100px;
            border: 3px solid rgb(255, 0, 43);
        }
    </style>
</head>

<body>
    <!-- 冒泡：从子节点往外父节点执行逻辑的行为是，冒泡事件。 -->
    <div id="div1">
        <div id="div2">
            <div id="div3"></div>
        </div>
    </div>

    <script>
        let div1Ele = document.getElementById('div1');
        let div2Ele = document.getElementById('div2');
        let div3Ele = document.getElementById('div3');

        div1Ele.addEventListener('click', function () {
            console.log('grandfather');
        });

        div2Ele.addEventListener('click', function () {
            console.log('father');
        });

        div3Ele.addEventListener('click', function (event) {
            event.stopPropagation();    //阻止事件冒泡（）
            console.log('son');
        });
    </script>
</body>

</html>